package com.lyf.scm.plan.domain.repository;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.plan.api.dto.SalesPlanOtherAccuracyDTO;
import com.lyf.scm.plan.domain.convertor.SalesPlanOtherAccuracyConvertor;
import com.lyf.scm.plan.domain.convertor.SalesPlanOtherAccuracySelectConvertor;
import com.lyf.scm.plan.insfrastructure.db.dataobject.SalesPlanOtherAccuracyDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.SalesPlanSelectDO;
import com.lyf.scm.plan.insfrastructure.db.mapper.SalesPlanOtherAccuracyMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 * 其他渠道计划_目标与销售计划准确率资源库
 *
 * @author: huangtao
 * @data: 2020/7/31
 */
@Service
public class SalesPlanOtherAccuracyRespository {

    @Resource
    private SalesPlanOtherAccuracyConvertor salesPlanOtherAccuracyConvertor;
    @Resource
    private SalesPlanOtherAccuracySelectConvertor salesPlanOtherAccuracySelectConvertor;
    @Resource
    private SalesPlanOtherAccuracyMapper salesPlanOtherAccuracyMapper;


    /**
     * 按条件其他渠道计划_目标与销售计划准确率
     * @param slaesPlanOtherAccuracy
     * @return
     */
    public PageInfo<SalesPlanOtherAccuracyDO> listWeekBySelective(SalesPlanOtherAccuracyDTO slaesPlanOtherAccuracy) {
        PageHelper.startPage(slaesPlanOtherAccuracy.getPageNum(), slaesPlanOtherAccuracy.getPageSize());
        SalesPlanSelectDO salesPlanSelectDO = salesPlanOtherAccuracySelectConvertor.dtoToDO(slaesPlanOtherAccuracy);
        return new PageInfo(salesPlanOtherAccuracyMapper.listWeekBySelective(salesPlanSelectDO));
    }

    public List<SalesPlanOtherAccuracyDTO> listAllByCondition(SalesPlanOtherAccuracyDTO slaesPlanOtherAccuracy) {
        return salesPlanOtherAccuracyConvertor.doToDTO(salesPlanOtherAccuracyMapper.listAllByCondition(salesPlanOtherAccuracySelectConvertor.dtoToDO(slaesPlanOtherAccuracy)));
    }

    /**
     * 查询其他渠道计划准确率指标
     * @param salesPlanSelectDO
     * @return
     */
    public List<SalesPlanOtherAccuracyDTO> listSalesAndTarget(SalesPlanOtherAccuracyDO salesPlanOtherAccuracyDO) {
        return salesPlanOtherAccuracyConvertor.doToDTO(salesPlanOtherAccuracyMapper.listSalesAndTarget(salesPlanOtherAccuracyDO));
    }

    /**
     * 按条件查询其他渠道计划准确率(周期)
     * @param slaesPlanOtherAccuracy
     * @return
     */
    public List<SalesPlanOtherAccuracyDTO> listAllByCycles(SalesPlanOtherAccuracyDTO slaesPlanOtherAccuracy) {
        return salesPlanOtherAccuracyConvertor.doToDTO(salesPlanOtherAccuracyMapper.listAllByCycles(salesPlanOtherAccuracySelectConvertor.dtoToDO(slaesPlanOtherAccuracy)));
    }

    public void delete(String opSign){
        salesPlanOtherAccuracyMapper.delete(opSign);
    }


    public void deleteByOpSign(String opSign) {
        salesPlanOtherAccuracyMapper.deleteByOpSign(opSign);
    }
}
